package com.tianqu.tms.www.transfer.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.FieldChecker;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.dto.MarketCarInfoDto;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.entity.CarStyle;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.entity.CommercialVehicle;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.entity.TransferPersonalCarInfo;
import com.tianqu.tms.entity.VehicleBrand;
import com.tianqu.tms.entity.Vendor;
import com.tianqu.tms.www.transfer.actionform.TransferRgActionForm;
import com.tianqu.tms.www.transfer.controller.CarRgInputConfirmController;
import com.tianqu.tms.www.transfer.viewhelper.TransferRgInputViewHelper;

/***
 * 
 * 过户受理
 * 
 * @author Administrator
 * 
 */
public class TransferRgInputConfirmAction extends TmsAction {

	private Logger logger = Logger.getLogger(TransferRgInputConfirmAction.class);

	private String carName;

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TransferRgActionForm inputForm = (TransferRgActionForm) form;
		TransferRgInputViewHelper view = (TransferRgInputViewHelper) uc.getAttribute(TmsConstants.VIEWHELP);
		view = convert(inputForm);
		
		request.setAttribute(TmsConstants.VIEWHELP, view);
		uc.setAttribute(TmsConstants.VIEWHELP, view);
		
		if("1".equals(inputForm.getSaveInputInfo())) {
			if (StringUtil.isNullOrBlank(inputForm.getSerial())) {
				String[] param = { "流水号" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}
			if (StringUtil.isNullOrBlank(inputForm.getVin())) {
				String[] param = { "车架号" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

//			if (StringUtil.isNullOrBlank(inputForm.getLicensePlate())) {
//				String[] param = { "车牌号码" };
//				setErrorsToRequest(request, TmsConstants.U0005, param);
//				return mapping.getInputForward();
//			}

			if (StringUtil.isNullOrBlank(inputForm.getVendorCode()) || StringUtil.isNullOrBlank(inputForm.getModelCode())) {
				String[] param = { "厂牌型号" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getCarType())) {
				String[] param = { "车辆类型" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getCountryStyle())) {
				String[] param = { "国别" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getCarUse())) {
				String[] param = { "使用性质" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getCardType())) {
				String[] param = { "号牌种类" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getRegDate())) {
				String[] param = { "登记日期" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getGainType())) {
				String[] param = { "购买方式" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getCarMarketIn())) {
				String[] param = { "车管所" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getPrice())) {
				String[] param = { "交易价格" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getIdentification())) {
				String[] param = { "原车主身份证/代码证" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getCarOwner())) {
				String[] param = { "原车主姓名" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getOwnerPhone())) {
				String[] param = { "原车主电话" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getNewIdentification())) {
				String[] param = { "新车主身份证/代码证" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getNewCarOwner())) {
				String[] param = { "新车主姓名" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getChangeBody())) {
				String[] param = { "审档方式" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			
			if (StringUtil.isNullOrBlank(inputForm.getNewOwnerPhone())) {
				String[] param = { "新车主电话" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getNewOwnerAddress())) {
				String[] param = { "新车主地址" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if (StringUtil.isNullOrBlank(inputForm.getZipCode())) {
				String[] param = { "新车主邮编" };
				setErrorsToRequest(request, TmsConstants.U0005, param);
				return mapping.getInputForward();
			}

			if(inputForm.getCarOwner().length() >= 5) {
				if (StringUtil.isNullOrBlank(inputForm.getAgentOwnerIdCardNo())) {
					String[] param = { "原车主代理人身份证" };
					setErrorsToRequest(request, TmsConstants.U0005, param);
					return mapping.getInputForward();
				}
				if (StringUtil.isNullOrBlank(inputForm.getAgentName())) {
					String[] param = { "原车主代理人姓名" };
					setErrorsToRequest(request, TmsConstants.U0005, param);
					return mapping.getInputForward();
				}
				if (StringUtil.isNullOrBlank(inputForm.getOwnerPhone())) {
					String[] param = { "原车主代理人电话" };
					setErrorsToRequest(request, TmsConstants.U0005, param);
					return mapping.getInputForward();
				}
			}
			
	        if(inputForm.getNewCarOwner().length() >= 5) {
	        	if (StringUtil.isNullOrBlank(inputForm.getNewAgentOwnerIdCardNo())) {
					String[] param = { "新车主身份证/代码证" };
					setErrorsToRequest(request, TmsConstants.U0005, param);
					return mapping.getInputForward();
				}
				if (StringUtil.isNullOrBlank(inputForm.getNewCarOwner())) {
					String[] param = { "新车主姓名" };
					setErrorsToRequest(request, TmsConstants.U0005, param);
					return mapping.getInputForward();
				}
				if (StringUtil.isNullOrBlank(inputForm.getNewOwnerPhone())) {
					String[] param = { "新车主电话" };
					setErrorsToRequest(request, TmsConstants.U0005, param);
					return mapping.getInputForward();
				}
			}
	        
	        if(inputForm.getVin().length() < 6 || inputForm.getVin().length() > 17 || !FieldChecker.isAlphabetNumericalSt(inputForm.getVin())) {
	        	String[] param = { "车架号" };
				setErrorsToRequest(request, TmsConstants.U1051, param);
				return mapping.getInputForward();
	        }
			
	        if (!StringUtil.isNullOrBlank(inputForm.getOwnerPhone())) {
				// 长度是11位的check
				if (!FieldChecker.checkLength(inputForm.getOwnerPhone(), 11, 11)) {
					String[] param = { "原车主电话","11" };
					setErrorsToRequest(request, TmsConstants.U0035, param);
					return mapping.getInputForward();
				}
				// 值是数字
				if (!FieldChecker.isNumericalSt(inputForm.getOwnerPhone())) {
					String[] param = { "原车主电话","11" };
					setErrorsToRequest(request, TmsConstants.U0035, param);
					return mapping.getInputForward();
				}
			}
	        
	        if (!StringUtil.isNullOrBlank(inputForm.getAgentPhone())) {
				// 长度是11位的check
				if (!FieldChecker.checkLength(inputForm.getAgentPhone(), 11, 11)) {
					String[] param = { "原车主代理人电话","11" };
					setErrorsToRequest(request, TmsConstants.U0035, param);
					return mapping.getInputForward();
				}
				// 值是数字
				if (!FieldChecker.isNumericalSt(inputForm.getAgentPhone())) {
					String[] param = { "原车主代理人电话","11" };
					setErrorsToRequest(request, TmsConstants.U0035, param);
					return mapping.getInputForward();
				}
			}
	        
	        if (!StringUtil.isNullOrBlank(inputForm.getNewOwnerPhone())) {
				// 长度是11位的check
				if (!FieldChecker.checkLength(inputForm.getNewOwnerPhone(), 11, 11)) {
					String[] param = { "新车主代理人电话","11" };
					setErrorsToRequest(request, TmsConstants.U0035, param);
					return mapping.getInputForward();
				}
				// 值是数字
				if (!FieldChecker.isNumericalSt(inputForm.getNewOwnerPhone())) {
					String[] param = { "新车主代理人电话","11" };
					setErrorsToRequest(request, TmsConstants.U0035, param);
					return mapping.getInputForward();
				}
			}
	        
	        if (!StringUtil.isNullOrBlank(inputForm.getNewOwnerPhone())) {
				// 长度是11位的check
				if (!FieldChecker.checkLength(inputForm.getNewOwnerPhone(), 11, 11)) {
					String[] param = { "新车主代理人电话","11" };
					setErrorsToRequest(request, TmsConstants.U0035, param);
					return mapping.getInputForward();
				}
				// 值是数字
				if (!FieldChecker.isNumericalSt(inputForm.getNewOwnerPhone())) {
					String[] param = { "新车主代理人电话","11" };
					setErrorsToRequest(request, TmsConstants.U0035, param);
					return mapping.getInputForward();
				}
			}
			
	        if(!DateUtil.isValidDate(inputForm.getRegDate())){
				String[] param = {"登记日期", "YYYYMMDD"};
				setErrorsToRequest(request, TmsConstants.U0018, param); 
				return mapping.getInputForward();
			}else{
				SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
				// 当前系统日期
				String nowDateStr = formatDate.format(new Date());
				Date nowDate = formatDate.parse(nowDateStr);
				// 有效结束日期	
				Date regDate = formatDate.parse(inputForm.getRegDate());
				if (regDate.compareTo(nowDate) >= 0) {
					String[] param = {"登记日期"};
					setErrorsToRequest(request, TmsConstants.U0020, param); 
					return mapping.getInputForward();
				}	
			}
		}else if("3".equals(inputForm.getSaveInputInfo())) {
		   String ip = request.getHeader("x-forwarded-for");
	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
	           ip = request.getHeader("Proxy-Client-IP");
	       }
	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
	           ip = request.getHeader("WL-Proxy-Client-IP");
	       }
	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
	           ip = request.getRemoteAddr();
	       }
	       String picPoint=inputForm.getUploadPic();
	       String sysPath = request.getSession().getServletContext().getRealPath("/").replace("/tmsweb", "");
		   uc.setAttribute("serial", view.getSerial());
		   uc.setAttribute("sysPath", sysPath);
		   uc.setAttribute("localIp", ip);
		   uc.setAttribute("picPoint", picPoint);
		}
		
        CarRgInputConfirmController controller = new CarRgInputConfirmController();
     	controller.execute(uc);
		 
		logger.debug(this.getClass().getName() + "#execute was completed.");
		
		if("1".equals(inputForm.getSaveInputInfo())) {
			view.setPrintBsflag("1");
			return mapping.findForward("print");//print
		}
		if("2".equals(inputForm.getSaveInputInfo()) || "3".equals(inputForm.getSaveInputInfo())) 
			return mapping.findForward("save");//save
		
		else return mapping.findForward(TmsConstants.SUCCESS);
	}

	private TransferRgInputViewHelper convert(TransferRgActionForm form) throws TmsDaoException {
		TransferRgInputViewHelper view = new TransferRgInputViewHelper();
		view.setSerial(form.getSerial());
		view.setVin(form.getVin());
		view.setLicensePlate(form.getLicensePlate());
		if (StringUtil.isNotBlank(form.getTransfer())) view.setTransfer(Integer.parseInt(form.getTransfer()));
		view.setStatus(form.getStatus());
		view.setMaterialImages1(form.getMaterialImages1());
		view.setMaterialImages2(form.getMaterialImages2());
		view.setMaterialImages3(form.getMaterialImages3());
		view.setMaterialImages4(form.getMaterialImages4());
		view.setMaterialImages5(form.getMaterialImages5());
		view.setMaterialImages6(form.getMaterialImages6());
		view.setMaterialImages7(form.getMaterialImages7());
		view.setMaterialImages8(form.getMaterialImages8());
		view.setMaterialImages9(form.getMaterialImages9());
		view.setMaterialImages10(form.getMaterialImages10());
		view.setNewAgentAddress(form.getNewAgentAddress());
		view.setAuditInfo(form.getAuditInfo());
		view.setNewAgentPhone(form.getNewAgentPhone());
		view.setNewAgentPhone(form.getNewAgentName());
		view.setCy_printTime(form.getCy_printTime());
		view.setNewAgentOwnerIdCardNo(form.getNewAgentOwnerIdCardNo());
		view.setNewOwnerAddress(form.getNewOwnerAddress());
		view.setNewOwnerPhone(form.getNewOwnerPhone());
		view.setNewCarOwner(form.getNewCarOwner());
		view.setNewOwnerOrgNo(form.getNewOwnerOrgNo());
		view.setNewOwnerOrgNo(form.getNewcarOwnerIdCardNo());
		view.setNewOwnerType(form.getNewOwnerType());
		view.setAgentAddress(form.getAgentAddress());
		view.setAgentPhone(form.getAgentPhone());
		view.setAgentName(form.getAgentName());
		view.setAgentOwnerIdCardNo(form.getAgentOwnerIdCardNo());
		view.setOwnerAddress(form.getOwnerAddress());
		view.setOwnerPhone(form.getOwnerPhone());
		view.setCarOwner(form.getCarOwner());
		view.setSerial(form.getSerial());
		view.setLicensePlate(form.getLicensePlate());
		view.setVin(form.getVin());
		view.setCarType(form.getCarType());
		view.setCountryStyle(form.getCountryStyle());
		view.setCarUse(form.getCarUse());
		view.setCy_cardType(form.getCardType());
		view.setRegisterCardNo(form.getRegisterCardNo());
		view.setRegDate(form.getRegDate());
		view.setGainType(form.getGainType());
		view.setPrice(StringUtil.addDH(form.getPrice()));
		view.setVendorCode(form.getVendorCode());
		view.setModelCode(form.getModelCode());
		view.setOwnerType(form.getOwnerType());
		view.setCarOwnerIdCardNo(form.getCarOwnerIdCardNo());
		view.setOwnerOrgNo(form.getOwnerOrgNo());
		view.setLicensePlate(form.getLicensePlate());
		view.setVin(form.getVin());
		view.setAgentName(form.getAgentName());
		view.setAgentOwnerIdCardNo(form.getAgentOwnerIdCardNo());
		view.setAgentAddress(form.getAgentAddress());
		view.setAgentPhone(form.getAgentPhone());
		view.setOwnersGroupPhoto(form.getOwnersGroupPhoto());
		view.setNewOwnerType(String.valueOf(form.getNewOwnerType()));
		view.setNewCarOwner(form.getNewCarOwner());
		view.setNewcarOwnerIdCardNo(form.getNewcarOwnerIdCardNo());
		view.setNewOwnerOrgNo(form.getNewOwnerOrgNo());
		view.setNewOwnerAddress(form.getNewOwnerAddress());
		view.setNewOwnerPhone(form.getNewOwnerPhone());
		view.setNewAgentPhone(form.getNewAgentPhone());
		view.setNewAgentName(form.getNewAgentName());
		view.setNewAgentOwnerIdCardNo(form.getNewAgentOwnerIdCardNo());
		view.setNewAgentAddress(form.getNewAgentAddress());
		view.setGainType(String.valueOf(form.getGainType()));
		view.setCarMarketIn(form.getCarMarketIn());
		view.setMoveOutProvince(form.getMoveOutProvince());
		view.setMoveOutCity(form.getMoveOutCity());
		view.setNewOwnerTelPhone(form.getNewOwnerTelPhone());
		if(StringUtil.isNotBlank(form.getPrice())) view.setPrice(String.valueOf(form.getPrice()));
		view.setTaxNo(form.getTaxNo());
		view.setIdentification(form.getIdentification());
		view.setNewIdentification(form.getNewIdentification());
		view.setRemark(form.getRemark());
		Codes code = Codes.getInstance();
		view.setCarType(form.getCarType());
		view.setCountryStyle(form.getCountryStyle());
		view.setCarUse(form.getCarUse());
		view.setCardType(form.getCardType());
		view.setGainType(form.getGainType());
		view.setZipCode(form.getZipCode());
		view.setCarOwnerIdCardNo(form.getCarOwnerIdCardNo());
		view.setChangeBody(form.getChangeBody());
		if(StringUtil.isNotBlank(form.getChangeBody()))  view.setChangeBodyName(code.getItemValueByItemIdAndItemCode(Codes.CHANGE_BODY_TYPE, Integer.parseInt(form.getChangeBody())));
		if(StringUtil.isNotBlank(form.getTransfer())) view.setTransfer(Integer.parseInt(form.getTransfer()));
		if(StringUtil.isNotBlank(form.getTransferRegister())) view.setTransferRegister(Integer.parseInt(form.getTransferRegister()));
		if(StringUtil.isNotBlank(form.getCarType())) view.setCarTypeName(code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_TYPE, Integer.parseInt(form.getCarType())));
		if(StringUtil.isNotBlank(form.getCountryStyle())) view.setCountryStyleName(code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_COUNTRY,Integer.parseInt(form.getCountryStyle())));
		if(StringUtil.isNotBlank(form.getCarUse())) view.setCarUseName(code.getItemValueByItemIdAndItemCode(Codes.USER_NATURE,Integer.parseInt(form.getCarUse())));
		if(StringUtil.isNotBlank(form.getCardType())) view.setCardTypeName(code.getItemValueByItemIdAndItemCode(Codes.PLATE_TYPE, Integer.parseInt(form.getCardType())));
		if(StringUtil.isNotBlank(form.getGainType())) view.setGainTypeName(code.getItemValueByItemIdAndItemCode(Codes.GAIN_TYPE,Integer.parseInt(form.getGainType())));
		view.setCardType(form.getCardType());
		view.setCarType(form.getCarType());
		view.setChangeBodyName(code.getItemValueByItemIdAndItemCode(Codes.CHANGE_BODY_TYPE,Integer.parseInt(form.getChangeBody())));
		if(StringUtils.isNotBlank(form.getCarType()) && StringUtils.isNumeric(form.getCarType()))  view.setCarTypeName(code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_TYPE,Integer.parseInt(form.getCarType())));
		if(StringUtils.isNotBlank(form.getCarMarketIn())) {
			MarketCarInfoDto info = Car.getInstance().getCtiyInfo(form.getCarMarketIn());
			if(info!=null) view.setMarketName(info.getVaoName());
		}
		view.setSpecialProcess(form.getSpecialProcess());
		if("2".equals(form.getTransfer())|| "5".equals(form.getTransferType())) view.setIsEditCarownerInfoEdit(1);//原车主可编辑
		else view.setIsEditCarownerInfoEdit(2);
		view.setStatus(form.getStatus());
		return view;
	}

	/**
	 * 将页面form信息set到viewhelp中
	 * 
	 * @throws TmsDaoException
	 */
	private TransferRgInputViewHelper setViewFromForm(TransferRgActionForm form, TransferRgInputViewHelper view)
			throws TmsDaoException {
		VehicleBrand brand = VehicleBrand.getInstance();
		// 车辆名称取值
		CommercialVehicle commercialVehicle = CommercialVehicle.getInstance();
		if (StringUtil.isNullOrBlank(form.getBrandId())) {
			setCarName(" ");
		} else {
			List list = new ArrayList();
			if (form.getFromType() == 1) {
				list = brand.getAllVehicleBrandInfo(form.getVendorId());
			} else {
				list = commercialVehicle.getAllVehicleBrandInfo(form.getVendorId());
			}
			if (list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					Map map = (Map) list.get(i);
					if (map.get("brandId").equals(form.getBrandId())) {
						String carName = (String) map.get("brandName");
						setCarName(carName);
					}
				}
			} else {
				setCarName(" ");
			}
		}

		if (StringUtil.isNotBlank(carName))
			view.setCarName(carName);
		view.setEngine(form.getEngine());
		if (form.getColor() != null && !"".equals(form.getColor())) {
			view.setColor(form.getColor());
		} else {
			view.setColor("");
		}
		view.setRegDate(form.getRegDate());
		view.setVendorCode(form.getVendorCode());
		view.setModelCode(form.getModelCode());

		if (form.getCarUse() != null && !"".equals(form.getCarUse())) {
			view.setCarUse(form.getCarUse());
		} else {
			view.setCarUse("");
		}
		if (form.getCarType() != null && !"".equals(form.getCarType())) {
			view.setCarType(form.getCarType());
		} else {
			view.setCarType("");
		}

		view.setSendCardDate(form.getSendCardDate());
		if (form.getCardType() != null && !"".equals(form.getCardType())) {
			view.setCardType(form.getCardType());
		} else {
			view.setCardType("");
		}
		view.setRegisterCardNo(form.getRegisterCardNo());
		if (form.getCountryStyle() != null && !"".equals(form.getCountryStyle())) {
			view.setCountryStyle(form.getCountryStyle());
		} else {
			view.setCountryStyle("");
		}
		view.setCompanyContactPerson(form.getCompanyContactPerson());
		view.setCarOwnerIdCardNo(form.getCarOwnerIdCardNo());
		view.setOwnerOrgNo(form.getOwnerOrgNo());
		view.setOwnerType(form.getOwnerType());
		view.setOwnerPhone(form.getOwnerPhone());
		view.setOwnerAddress(form.getOwnerAddress());
		view.setOwnerOrgNo(form.getOwnerOrgNo());
		view.setCarOwner(form.getCarOwner());
		view.setCarOwnerIdCardNoOld(form.getCarOwnerIdCardNoOld());
		view.setOwnerAddressOld(form.getOwnerAddressOld());
		view.setAgentName(form.getAgentName());
		view.setAgentOwnerIdCardNo(form.getAgentOwnerIdCardNo());
		view.setAgentAddress(form.getAgentAddress());
		view.setAgentPhone(form.getAgentPhone());
		view.setBrandId(form.getBrandId());
		view.setCarStyleId(form.getCarStyleId());
		view.setVendorId(form.getVendorId());

		view.setMaterialImages1(form.getMaterialImages1());
		view.setMaterialImages2(form.getMaterialImages2());
		view.setMaterialImages3(form.getMaterialImages3());
		view.setMaterialImages4(form.getMaterialImages4());
		view.setMaterialImages5(form.getMaterialImages5());
		view.setOwnersGroupPhoto(form.getOwnersGroupPhoto());

		view.setImageBsFlag("0");

		/*** 追加部分 **/
		view.setNewOwnerType(form.getNewOwnerType());
		view.setNewCarOwner(form.getNewCarOwner());
		view.setNewcarOwnerIdCardNo(form.getNewcarOwnerIdCardNo());
		view.setNewOwnerOrgNo(form.getNewOwnerOrgNo());
		view.setNewOwnerAddress(form.getNewOwnerAddress());
		view.setNewOwnerPhone(form.getNewOwnerPhone());

		view.setZipCode(form.getZipCode());
		view.setMailAddress(form.getMailAddress());
		view.setNewAgentPhone(form.getNewAgentPhone());
		view.setNewAgentName(form.getNewAgentName());
		view.setNewAgentOwnerIdCardNo(form.getNewAgentOwnerIdCardNo());
		view.setNewAgentAddress(form.getNewAgentAddress());
		view.setGainType(String.valueOf(form.getGainType()));
		view.setCarMarketIn(form.getCarMarketIn());
		view.setMoveOutProvince(form.getMoveOutProvince());
		view.setMoveOutCity(form.getMoveOutCity());
		view.setTransferType(form.getTransferType());// * 受理事项
		view.setNewOwnerTelPhone(form.getNewOwnerTelPhone());// 固话
		view.setTransferPrice(form.getTransferPrice());
		view.setPrice(form.getPrice());
		view.setTaxNo(form.getTaxNo());
		view.setIdentification(form.getIdentification());
		view.setNewIdentification(form.getNewIdentification());
		if (form.getAttnId() != null && !"".equals(form.getAttnId())) {
			view.setAttnId(form.getAttnId());
		}

		view.setRemark(form.getRemark());
		view.setAccessCardId(form.getAccessCardId());

		// 车辆品牌
		Vendor vendor = Vendor.getInstance();
		CarStyle carStyle = CarStyle.getInstance();
		view.setFromType(form.getFromType());
		if (form.getFromType() == 1) {
			view.setVendorList(vendor.findAllVendorInfo());
			view.setCarStyleList(carStyle.getAllCarStyleInfo(form.getBrandId()));
			view.setBrandList(brand.getAllVehicleBrandInfo(form.getVendorId()));
		} else {
			view.setVendorList(commercialVehicle.findAllVendorInfo());
			view.setCarStyleList(commercialVehicle.getAllStyleInfo(form.getBrandId()));
			view.setBrandList(commercialVehicle.getAllVehicleBrandInfo(form.getVendorId()));
		}
		view.setSourceType(form.getSourceType());
		if (StringUtil.isNullOrBlank(view.getMemberName())) {
			view.setMemberId(form.getMemberId());
		}
		return view;
	}

	/**
	 * 从Entity 给viewHelper 赋值
	 * 
	 * @param viewHelper
	 * @param car
	 * @throws TmsDaoException
	 */
	private TransferRgInputViewHelper setViewhelperFromEntity(TransferRgInputViewHelper view, Car car)
			throws TmsDaoException {

		// view.setVin(car.getVin());
		view.setEngine(car.getEngine());
		if (car.getColor() > 0) {
			view.setColor(String.valueOf(car.getColor()));
		} else {
			view.setColor("");
		}
		view.setRegDate(car.getRegDate());
		view.setVendorCode(car.getVendorCode());
		view.setModelCode(car.getModelCode());

		if (car.getCarUse() > 0) {
			view.setCarUse(String.valueOf(car.getCarUse()));
		} else {
			view.setCarUse("");
		}
		if (car.getCarType() > 0) {
			view.setCarType(String.valueOf(car.getCarType()));
		} else {
			view.setCarType("");
		}
		view.setSendCardDate(car.getSendCardDate());
		if (car.getCardType() >= 0) {
			view.setCardType(String.valueOf(car.getCardType()));
		} else {
			view.setCardType("");
		}
		view.setRegisterCardNo(car.getRegisterCardNo());
		if (car.getCountryStyle() >= 0) {
			view.setCountryStyle(String.valueOf(car.getCountryStyle()));
		} else {
			view.setCountryStyle("");
		}

		view.setCompanyContactPerson(car.getCompanyContactPerson());
		view.setCarOwnerIdCardNo(car.getCarOwnerIdCardNo());
		view.setOwnerOrgNo(car.getOwnerOrgNo());

		view.setOwnerPhone(car.getOwnerPhone());
		view.setOwnerAddress(car.getOwnerAddress());
		view.setOwnerOrgNo(car.getOwnerOrgNo());
		view.setCarOwner(car.getCarOwner());
		view.setBrandId(car.getBrandId());
		view.setCarStyleId(car.getCarStyleId());
		view.setVendorId(car.getVendorId());

		view.setImageBsFlag("0");

		if (car.getVendorId() != null && !"".equals(car.getVendorId())) {
			// 车辆品牌
			Vendor vendor = Vendor.getInstance();
			CarStyle carStyle = CarStyle.getInstance();
			VehicleBrand brand = VehicleBrand.getInstance();
			CommercialVehicle commercialVehicle = CommercialVehicle.getInstance();
			String str = car.getVendorId().substring(0, 1);
			if ("S".equals(str)) {
				view.setFromType(1);
				view.setVendorList(vendor.findAllVendorInfo());
				view.setCarStyleList(carStyle.getAllCarStyleInfo(car.getBrandId()));
				view.setBrandList(brand.getAllVehicleBrandInfo(car.getVendorId()));
			} else {
				view.setFromType(2);
				view.setVendorList(commercialVehicle.findAllVendorInfo());
				view.setCarStyleList(commercialVehicle.getAllStyleInfo(car.getBrandId()));
				view.setBrandList(commercialVehicle.getAllVehicleBrandInfo(car.getVendorId()));
			}
		}

		return view;
	}

	/**
	 * 从Entity 给viewHelper 赋值
	 * 
	 * @param viewHelper
	 * @param car
	 * @throws TmsDaoException
	 */
	private TransferRgInputViewHelper setViewhelperFromEntity1(TransferRgInputViewHelper view,
			TransferPersonalCarInfo personal) throws TmsDaoException {

		view.setEngine(personal.getEngine());
		if (personal.getColor() > 0) {
			view.setColor(String.valueOf(personal.getColor()));
		} else {
			view.setColor("");
		}
		view.setRegDate(personal.getRegDate());
		view.setVendorCode(personal.getVendorCode());
		view.setModelCode(personal.getModelCode());

		if (personal.getCarUse() > 0) {
			view.setCarUse(String.valueOf(personal.getCarUse()));
		} else {
			view.setCarUse("");
		}
		if (personal.getCarType() > 0) {
			view.setCarType(String.valueOf(personal.getCarType()));
		} else {
			view.setCarType("");
		}

		view.setSendCardDate(personal.getSendCardDate());
		if (personal.getCardType() >= 0) {
			view.setCardType(String.valueOf(personal.getCardType()));
		} else {
			view.setCardType("");
		}
		view.setRegisterCardNo(personal.getRegisterCardNo());
		if (personal.getCountryStyle() >= 0) {
			view.setCountryStyle(String.valueOf(personal.getCountryStyle()));
		} else {
			view.setCountryStyle("");
		}

		view.setCompanyContactPerson(personal.getCompanyContactPerson());
		view.setCarOwnerIdCardNo(personal.getCarOwnerIdCardNo());
		view.setOwnerOrgNo(personal.getOwnerOrgNo());

		view.setOwnerPhone(personal.getOwnerPhone());
		view.setOwnerAddress(personal.getOwnerAddress());
		view.setOwnerOrgNo(personal.getOwnerOrgNo());
		view.setCarOwner(personal.getCarOwner());
		view.setBrandId(personal.getBrandId());
		view.setCarStyleId(personal.getCarStyleId());
		view.setVendorId(personal.getVendorId());

		view.setImageBsFlag("0");

		if (personal.getVendorId() != null && !"".equals(personal.getVendorId())) {
			// 车辆品牌
			Vendor vendor = Vendor.getInstance();
			CarStyle carStyle = CarStyle.getInstance();
			VehicleBrand brand = VehicleBrand.getInstance();
			CommercialVehicle commercialVehicle = CommercialVehicle.getInstance();
			String str = personal.getVendorId().substring(0, 1);
			if ("S".equals(str)) {
				view.setFromType(1);
				view.setVendorList(vendor.findAllVendorInfo());
				view.setCarStyleList(carStyle.getAllCarStyleInfo(personal.getBrandId()));
				view.setBrandList(brand.getAllVehicleBrandInfo(personal.getVendorId()));
			} else {
				view.setFromType(2);
				view.setVendorList(commercialVehicle.findAllVendorInfo());
				view.setCarStyleList(commercialVehicle.getAllStyleInfo(personal.getBrandId()));
				view.setBrandList(commercialVehicle.getAllVehicleBrandInfo(personal.getVendorId()));
			}
		}

		return view;
	}

	public String getCarName() {
		return carName;
	}

	public void setCarName(String carName) {
		this.carName = carName;
	}

	private TransferRgInputViewHelper setViewFromAccept(TransferRgInputViewHelper view, TransferAcceptedInfo accept) throws TmsDaoException {
		if (accept.getNewOwnerType() > 0) {
			view.setNewOwnerType(String.valueOf(accept.getNewOwnerType()));
		}
		view.setNewCarOwner(accept.getNewcarOwner());
		view.setNewcarOwnerIdCardNo(accept.getNewcarOwnerIdCardNo());
		view.setNewOwnerOrgNo(accept.getNewOwnerOrgNo());
		view.setNewOwnerAddress(accept.getNewOwnerAddress());
		view.setNewOwnerPhone(accept.getNewOwnerPhone());
		view.setZipCode(accept.getNewOwnerZipCode());
		view.setMailAddress(accept.getNewOwnerMailAddress());
		view.setNewAgentPhone(accept.getNewAgentPhone());
		view.setNewAgentName(accept.getNewAgentName());
		view.setNewAgentOwnerIdCardNo(accept.getNewAgentOwnerIdCardNo());
		view.setNewAgentAddress(accept.getNewAgentAddress());
		view.setGainType(String.valueOf(accept.getGainType()));
		view.setCarMarketIn(accept.getCarMarketIn());
		view.setMoveOutProvince(accept.getMoveOutProvince());
		view.setMoveOutCity(accept.getMoveOutCity());
		if (accept.getTransferType() > 0) {
			view.setTransferType(String.valueOf(accept.getTransferType()));// * 受理事项
		}
		view.setNewOwnerTelPhone(accept.getNewOwnerTelPhone());// 固话
		if (accept.getOwnerType() == 1) {
			view.setPriceBsFlag("");
		}

		return view;
	}
}
